package com.platform.qujia;

import com.google.gson.JsonObject;
import com.google.zxing.WriterException;
import com.platform.qujia.utils.DESUtils;
import com.platform.qujia.utils.HttpClientUtil;
import com.platform.qujia.utils.tonglianpay.SybPayService;
import com.platform.qujia.utils.tonglianpay.tlfusclasspay.TLFusClassPayUtil;
import com.platform.qujia.utils.tonglianpay.tlfusclasspay.struct.body.TLFusClassPayParam;
import com.platform.qujia.utils.tonglianpay.tlfusclasspay.struct.support.ConsumeType;
import com.platform.qujia.utils.tonglianpay.tlfusclasspay.struct.support.OilStation;
import com.platform.qujia.utils.tonglianpay.tlfusclasspay.util.SignUtils;
import com.platform.qujia.utils.weixinapp.WxTemplateData;
import com.platform.qujia.utils.weixinapp.WxTemplateMsg;
import com.saobei.open.sdk.util.MD5Util;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;

public class test {

    public static void main(String[] args) throws Exception {
//            Thread a = new Thread(()->{
//                System.out.println("线程 a " + Thread.currentThread().getName());
//                System.out.println("线程 a 运行结束...");
//            });
//            Thread b = new Thread(()->{
//                System.out.println("线程 b " + Thread.currentThread().getName());
//                try {
//                    Thread.currentThread().sleep(3000);
//                    System.out.println("线程 b sleep 3s ...");
//                    System.out.println("线程 b 运行结束...");
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//            });
//            b.start();
//            b.join();
//            a.start();

        String tokenCache = "53_h7vcgwf_l-jrN7068bA6mVj3ceFukeoaoDblMbia_7cMB1vr7dWOWnmqBdBRZw6IbNQzDYIDLpMr0R_1mTbJLavxS67UXbEJXFU_57nind16TBVM8A3W1NAKndrkqRh2ssGaLgkpG5bl4XBlDYOfAFAJEU";
        String send_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + tokenCache;
        WxTemplateMsg wxTemplateMsg = new WxTemplateMsg();
        wxTemplateMsg.setTemplate_id("WL2j9hZYvcTb2iuYNf9gxmCrLG-QIrkXPZcHM8osnJY"); //WL2j9hZYvcTb2iuYNf9gxmCrLG-QIrkXPZcHM8osnJY  // G9tN--a3tGM5BN3otqZr73b4ErQCYWISSgyshbTqLYc
        wxTemplateMsg.setTouser("oJR5R6r4EJhaORFcPap70r_mtFZo");        //oJR5R6n553PNkDIQphRSvI269w88  oJR5R6r4EJhaORFcPap70r_mtFZo  oJR5R6s1vCsUiI0wrdLEEXOY6Guo oJR5R6gWNpGre5hfPXkFvcdBhIrE oJR5R6jnQbTfEPCrBIeZCA13bm8A
        String url = "https://"+"mp.huijy.net"+"/"+ 7 +"/coupon";
        wxTemplateMsg.setUrl(url);
//        Map<String, WxTemplateData> templateDataMap = new HashMap<>();
//        templateDataMap.put("first",  WxTemplateData.builder().value("尊敬的曹操您好：您在智慧易加的积分最新交易信息如下").color("#173177").build());
//        templateDataMap.put("time",   WxTemplateData.builder().value(new SimpleDateFormat("yyyy年MM月dd日HH时mm分").format(new Date())).build());
//        templateDataMap.put("type",   WxTemplateData.builder().value("增加").build());
//        templateDataMap.put("Point",  WxTemplateData.builder().value("5555555").build());
//        templateDataMap.put("From",   WxTemplateData.builder().value("智慧易加").build());
//        templateDataMap.put("remark", WxTemplateData.builder().value("截止至" + new SimpleDateFormat(" yyyy年MM月dd日HH时mm分").format(new Date())+"，您在 智慧易加 的可用积分为  600000 分").build());
        Map<String, WxTemplateData> templateDataMap = new HashMap<>();
        templateDataMap.put("first",  WxTemplateData.builder().value("恭喜您获得优惠券，请点击查看").color("#0080FF").build());
        templateDataMap.put("keyword1",   WxTemplateData.builder().value("点击查看").color("#46A3FF").build());
        templateDataMap.put("keyword2",   WxTemplateData.builder().value(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())).color("#46A3FF").build());

        wxTemplateMsg.setData(templateDataMap);
        JSONObject jsonObject = HttpClientUtil.doPostJson(send_url, com.alibaba.fastjson.JSONObject.toJSONString(wxTemplateMsg));
        if(null !=jsonObject && jsonObject.containsKey("errcode") && "0".equals(jsonObject.get("errcode").toString())){
            System.out.println("发送成功");
        }else {
            System.out.println(jsonObject);
        }
      //  System.out.println(jsonObject);

//        LocalDate localDate = LocalDate.now().plusMonths(-1);
//        System.out.println(localDate);

//        TreeMap<String, String> map = new TreeMap<String, String>();
//        map.put("code", "SUCCESS");
//        map.put("msg", "SUCCESS");
//        map.put("bizCode", "0000");
//        map.put("bizMsg", "SUCCESS");
//        String key = "82995d03e8bb7e5f863f946ab937dc92";
//        map.put("key", key);
//        String sign = SignUtils.sign(map);
//        System.out.println(sign);

//        String shiftsStatTime ="17:30";
//        String shiftsEndTime ="07:30";
//        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
//        Date sst = sdf.parse("2022-01-29" + " " + "07:30:00");
//        Date set = sdf.parse("2022-01-29" + " " + "17:30:00");

//        Date sst1 = sdf.parse("2022-01-28" + " " + "17:30:00");
//        Date set1 = sdf.parse("2022-01-29" + " " + "07:30:00");
//        String string = "17:30:20";  //当前时间
//        String s1 = "17:30:22";
//        String s2 = "07:30:10";
//        String format = sdf.format(new Date());
//        if(string.compareTo(s1) >=0){
//            System.out.println("大");
//        }else {
//            System.out.println("小");
//        }

//        if(shiftsStatTime.compareTo(shiftsEndTime) <= 0){
//            System.out.println("开始时间小于结束时间");
//            if(now.compareTo(sst) >= 0 && now.compareTo(set) <0){
//                System.out.println("成功------------------");
//            }
//        }else{
//            System.out.println("开始时间大于结束时间");
//            if(now.compareTo(sst1) >=0 && now.compareTo(set1) <0){
//                System.out.println("成功");
//            }
//        }




//        LocalDate localDate = LocalDate.now();
//        String ss = "17:30:00";
//        String s = localDate.toString()+" "+ ss;
//        Boolean i = ss.substring(0, 2).compareTo("24") >=0;
//        System.out.println(i);
//        System.out.println(ss.substring(0,2));
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:dd:ss");
//        System.out.println(simpleDateFormat.format(new Date()));
//
//        SimpleDateFormat sdf = new SimpleDateFormat(s);
//        Date parse = sdf.parse(s);
//        System.out.println(parse.after(new Date()));
//
//        String format = simpleDateFormat.format(new Date());
//        System.out.println(format.compareTo("17:00:00")>=0);

//        TLFusClassPayParam payApply = new TLFusClassPayParam();
//        payApply.setTlAppId("M00000048");                               //AppId
//        payApply.setTlAppKey("87b7ea4b833040efae00496f5210eee6");       //appkey
//        payApply.setAccount("oWL5P5PPF5gFmoDid19Ij_nN5h70");            //微信openid oWL5P5PPF5gFmoDid19Ij_nN5h70，支付宝userId    2088902520645535
//        payApply.setSubAppId("wxb46701bd193ee573");                     //微信公众号/小程序appid wxb46701bd193ee573    2021002194660904
//        payApply.setSysId("1480833167961694210");                       //系统编号
//        payApply.setBizOrderNo(String.valueOf(System.currentTimeMillis()));
//        payApply.setAmount(1L);
//        payApply.setBackUrl("http://www.baidu.com");
//        payApply.setPayType("WECHATPAY_MINIPROGRAM");
//        //payApply.setLimitPay("no_credit");
////        List<ConsumeType> consumeTypes = new ArrayList<>();
////        ConsumeType consumeType = new ConsumeType();
////        consumeType.setType("C0001");
////        consumeType.setAmount(1L);
////        consumeTypes.add(consumeType);
////        payApply.setConsumeTypes(consumeTypes);
////        OilStation oilStation = new OilStation();
////        oilStation.setOilStationNo("S0015");
//        payApply.setTlOilStationNo("S0215");
////        payApply.setOilStation(oilStation);
//        payApply.setConsumeType("C0003");
//        payApply.setShiftsTime(DateFormatUtils.format(new Date(), "yyyyMMdd"));
//        payApply.setShiftsMask("2");
//        payApply.setRemark("这是备注");
//
//        HashMap hashMap = TLFusClassPayUtil.tLFusClassPayApply(payApply);
//        System.out.println(hashMap);
//        System.out.println(new SimpleDateFormat("yyyymmddhhmmss").parse("20211221153859"));
//        System.out.println(new SimpleDateFormat("yyyyMMddHHmmss").parse("20211221153859"));
//        System.out.println(new SimpleDateFormat("YYYYMMDDHHmmss").parse("20211221153859"));
//        SybPayService sybPayService = new SybPayService();
//        Map<String, String> pay = sybPayService.pay(
//                100,                                                    // 交易金额 （必填）
//                "553588055418RR8",                                      //商户号       （必填）
//                "00226421",                                         //通联给的appId     （必填）
//                //MD5Util.MD5Encode("huizhong12", "UTF-8"),    //MD5加密字符串密码   (必填)
//                String.valueOf(System.currentTimeMillis()),                     // 商户的交易订单号 （必填）
//                "W06",                                                  //交易方式  （必填）
//                "测试",                                                  //订单内容
//                "备注测试",                                             //备注
//                "ofBF05YUDPj2WsE7TNVkxyejELI0",                          //支付平台用户标识
//                "",                                                 //订单有效时间，以分为单位，不填默认为5分钟
//                "https://test.91cheyibao.com/apipay/tLCallBack",           //接收交易结果的异步通知回调地址，通知url必须为直接可访问的url，不能携带参数。
//                "",                                                 //no_credit--指定不能使用信用卡支付
//                "",                                             //实名交易必填.填了此字段就会验证证件号和姓名
//                "",                                             //实名交易必填.填了此字段就会验证证件号和姓名
//                "",
//                "wx60eecce847c74bcc",                       // 微信子appid 商户微信号 （微信必填）
//                "",                             //订单支付标识 只对微信有效
//                "",         //Benefitdetail的json字符串,注意是String； 仅支持微信单品优惠 W01交易方式不支持 支付宝智慧门店 支付宝单品优惠
//                "",          //渠道门店编号
//                "",          //门店编号
//                "",        //json字符串，注意是String 一般用于渠道的活动参数填写
//                "",              //用户下单和调起支付的终端ip地址
//                ""              //6-花呗分期6期 12-花呗分期12期
//        );
//        System.out.println(pay);
//        System.out.println(pay.get("payinfo"));


//        Calendar c = Calendar.getInstance();
//        Date time = c.getTime();
//        LocalDate localDate = new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//        System.out.println(localDate);
//        System.out.println(LocalDate.now());
//        System.out.println(LocalDate.now().plusDays(1));

//        TLPayUtil.payApply();

//        HashMap map = new HashMap();
//        Integer i = 5;
//        System.out.println(i.toString());
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd");
//        String format = dateFormat.format(new Date());
//        //format = format.substring(2);
//        System.out.println(format);

        //2、返回POS支付二维码；
//        String url = "https://goto.huijy.net/123/e21/l20/m1000/g8/";      //二维码跳转链接地址
//        String staStr = "123";                      //油站ID
//        BufferedImage bi = QRcodeUtils.createImage(url, null, false);
//        QRcodeUtils.encode(url, null, "d:/", false);
//        System.out.println(bi);
//        System.out.println(bi.getHeight() +"; "+ bi.getHeight());
//
//        ByteArrayOutputStream baos = new ByteArrayOutputStream();
//        ImageIO.write(bi, "png", baos);
//        String encode = Base64.encode(baos.toByteArray());
//        System.out.println(encode);
//        baos.flush();
//        baos.close();

//        Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2021-09-27 00:05:25");
//        System.out.println(parse);
//
//        Date parse1 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2021-09-27 00:05:25");
//        System.out.println(parse1);
//
//        new SimpleDateFormat("yyyyMMddHHmmss").parse("2021-09-27 00:05:25");


//        String yyyyMMddhhmmss = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date());
//        System.out.println(yyyyMMddhhmmss);
//
//        BigDecimal subtract = new BigDecimal("0").subtract(new BigDecimal("2"));
//        System.out.println(subtract);


//        BigDecimal discountPrice = new BigDecimal("5.52");
//        BigDecimal oilLiters = new BigDecimal("35.59");
//
//        BigDecimal amt = discountPrice.multiply(oilLiters);
//        System.out.println(amt);


//        BigDecimal driverDiscountAmt = sellDiscountAmt.multiply(new BigDecimal("1").subtract(new BigDecimal("97").divide(new BigDecimal("100"))));
//        System.out.println(driverDiscountAmt);


//        Date parse = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse("2021-04-24 22:22:22");
//        System.out.println(parse);

//        String location = LocationUtil.getLocation("117.12009", "36.65184");
//        System.out.println(location);
        //117.022388,36.667508
//        JSONObject locationInfo = BaiduMapUtil.getLocation("117.12009", "36.65184");
//        System.out.println(locationInfo);



//        String detailAddress = BaiduMapUtil.getDetailAddress("117.12009", "36.65184");
//        System.out.println(detailAddress);


//        BigDecimal discountPrice = new BigDecimal("5.36");
//        BigDecimal sellPrice = discountPrice.multiply(new BigDecimal("98")).divide(new BigDecimal("100"));
//        System.out.println(sellPrice.toString());


        //QRcodeUtils.encode();
        //QRcodeUtils.imgContainQRcode();

//        Thread_A a1 = new Thread_A("A线程");
//        Thread_B b2 = new Thread_B("B线程");
//
//        Thread t1 = new Thread(a1);
//        //t1.setPriority(10);
//        Thread t2 = new Thread(b2);
//        //t2.setPriority(1);
//        t1.start();
//        t2.start();


//
//        String data = "123456";
//        String pwd = "LAnZ8RRSkIY0EGVYheu2IjEk";
//        String encryptDataStr= DESUtils.encrypt(data, pwd);
//        System.out.println("加密后得到的密文......");
//        System.out.println(encryptDataStr);
//        String decryptDataStr=DESUtils.decrypt(encryptDataStr, pwd);
//        System.out.println("解密后得到的明文......");
//        System.out.println(decryptDataStr);




    }




    public static boolean isEqual(byte[] digesta, byte[] digestb) {
        if (digesta.length != digestb.length) {
            return false;
        }

        int result = 0;
        for (int i = 0; i < digesta.length; i++) {
            result |= digesta[i] ^ digestb[i];
            System.out.println(digesta[i] ^ digestb[i]);
            //System.out.println(result);
        }
        return result == 0;
    }



}
